package thread.threadpool;

import java.util.concurrent.*;

/**
 * @author lwmzzz
 * @version 1.0
 * @date 2021/5/19 23:39
 * @description
 */
public class Test03 {
    public static void main(String[] args) {

        BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(10);

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 0, TimeUnit.SECONDS, queue, Executors.defaultThreadFactory(),
                new RejectedExecutionHandler() {

                    @Override
                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                        System.out.println(r + " is discarded...");
                    }
                });
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            threadPoolExecutor.submit(() -> System.out.println(Thread.currentThread().getId()));
        }

    }
}
